package studio7Omega.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import studio7Omega.modelo.Sala;
import studio7Omega.negocio.SistemaNegocio;
import studio7Omega.excepcion.DAOExcepcion;



/**
 * Servlet implementation class SalaGuardarServlet
 */
@WebServlet("/SalaGuardarServlet")
public class SalaGuardarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SalaGuardarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String descripcion = request.getParameter("descripcion");
		String y = request.getParameter("capacidad");
		int capacidad= Integer.parseInt(y);
		
		String caracteristicas = request.getParameter("caracteristicas");
		String a = request.getParameter("costo");
		Double costo = Double.parseDouble(a);
		
		String b = request.getParameter("locales");
		int idlocal = Integer.parseInt(b);
		
		SistemaNegocio negocio = new SistemaNegocio();
		try {
			Sala salval = negocio.insertarSala(descripcion, capacidad, caracteristicas, costo, idlocal);
						
			request.setAttribute("SALA", salval);
			
			RequestDispatcher rd = request.getRequestDispatcher("registro_sala.jsp");
			rd.forward(request, response);
			
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}	
}

